<?php

declare(strict_types=1);

use function Hyperf\Support\env;

/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */


$registry = [
    'protocol' => 'nacos',
    'address' => 'http://'.env('NACOS_HOST','127.0.0.1').':'.env('NACOS_PORT',8848),
];

return [
    'enable' => [
        'discovery' => true,
        'register' => true,
    ],
    // 服务消费者
    'consumers' => [

        [
            // name 需与服务提供者的 name 属性相同
            'name' => 'yaoli-service-rpc-config',
            // 服务接口名，可选，默认值等于 name 配置的值，如果 name 直接定义为接口类则可忽略此行配置，如 name 为字符串则需要配置 service 对应到接口类
            'service' => \App\RpcConsumer\SystemConfigServiceInterface::class,
            // 对应容器对象 ID，可选，默认值等于 service 配置的值，用来定义依赖注入的 key
            'id' => \App\RpcConsumer\SystemConfigServiceInterface::class,
            // 使用 HTTP 传输协议
            'protocol' => 'jsonrpc-http',
            // 随机负载均衡 random
            'load_balancer' => 'random',
            'registry' => $registry,
            // 不使用服务发现，直连服务提供者
            // 'nodes' => [
            //     // ['host' => '127.0.0.1', 'port' => 9508],
            // ],
        ],
    ],
    // 服务提供者
    'providers' => [

    ],
    'drivers' => [
        'nacos' => [
            // nacos server url like https://nacos.hyperf.io, Priority is higher than host:port
            // 'url' => '',
            // The nacos host info
            'host' => env('NACOS_HOST', '127.0.0.1'),
            'port' => env('NACOS_PORT', 8848),
            // The nacos account info
            'username' => env('NACOS_USERNAME', null),
            'password' => env('NACOS_PASSWORD', null),
            'guzzle' => [
                'config' => null,
            ],
            'group_name' => env('NACOS_GROUP', 'DEFAULT_GROUP'),
            'namespace_id' => env('NACOS_NAMESPACE_ID', 'dev'),
            'heartbeat' => 5,
            'ephemeral' => true,
            'cluster' => env('NACOS_CLUSTER', 'DEFAULT'),
            // Only support for nacos v2.
            'grpc' => [
                'enable' => false,
                'heartbeat' => 10,
            ],
        ],
    ],
];
